//
//  NSAttributedStringHelper.swift
//  DictionaryModule
//
//  Created by xianquan on 2023/12/14.
//

import Foundation
public extension NSAttributedString{
    func sizeOfAttributedString(contentSize: CGSize) -> CGSize {
        boundingRect(with: contentSize, options: [.usesLineFragmentOrigin, .usesFontLeading], context: nil).size
    }
}

public extension NSAttributedString{
    static func makeArrtribiteStr(srcStr : String,keyWord : String, keywordColor : UIColor,textFont : UIFont) -> NSAttributedString{
        let arrtributeStr = NSMutableAttributedString(string: srcStr)
        arrtributeStr.yy_font = textFont
        let range = (arrtributeStr.string as NSString).range(of: keyWord)
        let keywordColor = keywordColor
        arrtributeStr.addAttribute(.foregroundColor, value: keywordColor, range: range)
        return arrtributeStr
    }
}
